<?php

class Controller
{
    
    public static function getCurrentSection()
    {
        if (isset($_GET['section']))
            return $_GET['section'];
        else
            return null;
    }
    
    public static function getCurrentAction()
    {
        if (isset($_GET['action']))
            return $_GET['action'];
        else
            return null;
    }
    
    public static function getCurrentParams()
    {
        if (isset($_GET['params']))
            return $_GET['params'];
        else
            return null;
    }
    
    public static function getUserVar($name)
    {
        if (isset($_GET[$name]))
            return $_GET[$name];
        else
            return null;
    }
    
    public static function getCurrentPath()
    {
        $path = Controller::getCurrentSection();
        if (Controller::getCurrentAction() != null) $path .= '/' . Controller::getCurrentAction();
        return $path;
    }
    
    public static function getCurrentUrl()
    {
        $path = '/' . Controller::getCurrentPath();
        if (Controller::getCurrentParams() != null) $path .= '/' . Controller::getCurrentParams();
        return $path;
    }
    
    public static function redirect($wait, $section, $action = null, $params = null)
    {
        $url = "/" . $section;
        if ($action)
        {
            $url .= "/" . $action;
            if ($params) $url .= "/" . $params;
        }
        Page::setRedirect($url, $wait);
    }
    
    public static function pushRedirect($wait, $section, $action = null, $params = null)
    {
        Controller::redirect($wait, $section, $action, $params);
    }
    
    public static function reload()
    {
        $currentUrl = Controller::getCurrentUrl();
        Page::setRedirect($currentUrl, 0);
    }
    
}

?>